package com.zq.product.controller;


import com.github.pagehelper.PageInfo;
import com.zq.common.util.Result;
import com.zq.product.dao.dto.ProductAddDto;
import com.zq.product.dao.dto.ProductSkuDto;
import com.zq.product.dao.entity.Brand;
import com.zq.product.dao.entity.Product;
import com.zq.product.dao.entity.ProductSku;
import com.zq.product.dao.dto.ProductDto;
import com.zq.product.dao.vo.ProductItemVo;
import com.zq.product.dao.vo.ProductVo;
import com.zq.product.service.IProductService;
import com.zq.product.service.IProductSkuService;
import io.swagger.v3.oas.annotations.Parameter;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 商品 前端控制器
 * </p>
 *
 * @author 张乔
 * @since 2025-05-13
 */
@RestController
@RequestMapping("/product/product")
@Slf4j
public class ProductController {


@Resource
private IProductService productService;









    //导出
    @GetMapping(value = "/exportData")
    public void exportData(HttpServletResponse response) {

        productService.exportData(response);
    }

    //    导入
    @PostMapping("/mportData")
    public Result<String> importData( MultipartFile file) {
        log.info("开始导入"+file.getName());
        productService.importData(file);
        return Result.success();
    }







//    商品分页查询
    @GetMapping(value = "/{page}/{limit}")
    public Result<PageInfo<ProductVo>> findByPage(@PathVariable Integer page,
                                                @PathVariable Integer limit,
                                                ProductDto productDto) {
        PageInfo<ProductVo> pageInfo = productService.
                findByPage(page, limit, productDto);
        return Result.successData(pageInfo);
    }
//    商品添加
@PostMapping("/save")
public Result<String> save(@RequestBody ProductAddDto productAddDto) {
    productService.addProduct(productAddDto);
    return Result.success() ;
}

//根据id获取商品
    @GetMapping("/getById/{id}")
    public Result<ProductVo> getById(@PathVariable Long id) {
        ProductVo productVo = productService.getByIdApi(id);
        return Result.successData(productVo);
    }

//根据id修改商品
    @PutMapping("/updateById")
    public Result<String> updateById(@RequestBody ProductVo productVo) {
        productService.updateByIdApi(productVo);
        return Result.success();
    }

//根据id删除商品
    @DeleteMapping("/deleteById/{id}")
    public Result<String> deleteById(@PathVariable Long id) {
        productService.deleteById(id);
        return Result.success() ;
    }

//根据id修改审核状态
    @GetMapping("/updateAuditStatus/{id}/{auditStatus}")
    public Result<String> updateAuditStatus(@PathVariable Long id,
                                            @PathVariable Integer auditStatus) {
        productService.updateAuditStatus(id, auditStatus);
        return Result.success();
    }

//根据id修改上架状态
    @GetMapping("/updateStatus/{id}/{status}")
    public Result<String> updateStatus(@PathVariable Long id,
                                       @PathVariable Integer status) {
        productService.updateStatus(id, status);
        return Result.success();
    }










}


















